package com.sinosoft.ci.patch.svn;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

import com.sinosoft.ci.patch.SrcEntryToPatchEntryConvertor;

/**
 * 从 SVN 中解析出 升级补丁
 * 
 * @author hancx_sinosoft
 *
 */
public class SvnPatchEntryExtractor {
	private File appRootDir;
	private long[] versions;
	private SvnModifiedEntryExtractor modifiedExtractor;
	private SrcEntryToPatchEntryConvertor entryConvertor;
	
	public SvnPatchEntryExtractor(File appRootDir){
		this.appRootDir = appRootDir;
	}
	
	public void setModifiedExtractor(SvnModifiedEntryExtractor e){
		modifiedExtractor = e;
	}
	
	public void setVersions(long[] versions){
		this.versions = versions;
	}
	
	public String[] getPatchEntry(){
		if(null == modifiedExtractor){
			throw new IllegalStateException("请先设置 SvnModifiedEntryExtractor!");
		}
		if(null == versions){
			throw new IllegalStateException("请先设置 versions!");
		}
		if(null == entryConvertor){
			throw new IllegalStateException("请先设置 SrcEntryToPatchEntryConvertor!");
		}
		String[] srcEntrys = modifiedExtractor.getSvnFileChangeEntrys(this.versions);
		List<String> result = new LinkedList<String>();
		
		for(String srcEntry : srcEntrys){
			String[] es = entryConvertor.convert(srcEntry);
			for(String e : es){
				result.add(e);
			}
		}
		
		return result.toArray(new String[result.size()]);
	}
}
